﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NS_QuangCaoTiepThiBUS
{
    public class PhongBUS
    {
        public void Them(Phong pDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            storeDB.Phongs.InsertOnSubmit(pDTO);

            storeDB.SubmitChanges();
        }

        public void Sua(Phong pDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.Phongs.Where(q => q.MaPhong == pDTO.MaPhong).First();

            query.TenPhong = pDTO.TenPhong;

            storeDB.SubmitChanges();
        }

        public void Xoa(Phong pDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.Phongs.Where(q => q.MaPhong == pDTO.MaPhong).First();

            storeDB.Phongs.DeleteOnSubmit(query);

            storeDB.SubmitChanges();
        }

        public IList<Phong> LayDanhSachPhong()
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.Phongs.ToList();

            return query;
        }

        public bool KiemTraTonTaiPhong(Phong pDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.Phongs.Where(q => q.MaPhong == pDTO.MaPhong).ToList();

            if (query.Count > 0)
            {
                return true;
            }

            return false;
        }
    }
}
